import request from '@/utils/request'

/**
 * 附件管理 API
 */

// 获取附件列表
export const getAttachmentList = (params: AttachmentQueryParams) => {
  return request.get<AttachmentListResponse>('/attachments', params)
}

// 获取附件详情
export const getAttachment = (id: number) => {
  return request.get<Attachment>(`/attachments/${id}`)
}

// 创建附件
export const createAttachment = (data: AttachmentCreateRequest) => {
  return request.post<Attachment>('/attachments', data)
}

// 更新附件
export const updateAttachment = (id: number, data: AttachmentUpdateRequest) => {
  return request.put<Attachment>(`/attachments/${id}`, data)
}

// 删除附件
export const deleteAttachment = (id: number) => {
  return request.delete<void>(`/attachments/${id}`)
}

// 批量删除附件
export const batchDeleteAttachments = (ids: number[]) => {
  return request.post<void>('/attachments/batch-delete', ids)
}

// 上传文件
export const uploadFile = (file: File, category?: string, extparam?: string) => {
  const formData = new FormData()
  formData.append('file', file)
  if (category) {
    formData.append('category', category)
  }
  if (extparam) {
    formData.append('extparam', extparam)
  }
  return request.upload<AttachmentUploadResponse>('/attachments/upload', formData)
}

// 获取类别列表
export const getCategories = () => {
  return request.get<string[]>('/attachments/categories')
}

// 获取存储引擎列表
export const getStorageEngines = () => {
  return request.get<string[]>('/attachments/storage-engines')
}
